package com.zx.cashiersystem.activity;

import android.os.Bundle;
import android.util.Log;

import com.zx.cashiersystem.device.InnerScannerSample;

/**
 * Created by Administrator on 2017/2/14.
 * 扫描
 */

public class InnerScannerActivity extends BaseActivity {
    private InnerScannerSample scannerSample;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        scannerSample = new InnerScannerSample(this) {

            @Override
            protected void onDeviceServiceCrash() {
                InnerScannerActivity.this.onDeviceServiceCrash();
            }

            @Override
            protected void displayDeviceInfo(String info) {
                Log.d("InnerScannerActivity", "扫描得到的info：" + info);
                InnerScannerActivity.this.displayInfo(info);
            }
        };
    }

    @Override
    protected void initView() {
        scannerSample.start();
    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected void initData() {

    }

    public void onDeviceServiceCrash() {
        bindDeviceService();
    }

    /**
     * All device operation result infomation will be displayed by this method.
     *
     * @param info
     */
    public void displayInfo(String info) {

    }

    @Override
    protected void onResume() {
        super.onResume();

        bindDeviceService();
    }

    /**
     * Sometimes you need to release the right of using device before other application 'onStart'.
     */
    @Override
    protected void onPause() {
        super.onPause();

        unbindDeviceService();

        // It's very important for release memory.
        scannerSample.stopListen();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        scannerSample.stop();
    }
}
